package cn.hzking.gjmall.adpters.order;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.bean.order.OrderDetailBean;
import cn.hzking.gjmall.utils.ListUtils;

/**
 * Created by Administrator on 2018/3/2.
 */

public class OrderDetailAdapter extends BaseQuickAdapter<OrderDetailBean.DataBean.OrderDOBean,BaseViewHolder> implements OrderDetailItemAdapter.ApplyRefundInterface{
    public OrderDetailAdapter(int layoutResId, @Nullable List<OrderDetailBean.DataBean.OrderDOBean> data) {
        super(layoutResId, data);
    }

    private OrderRefundInterface orderRefundInterface;

    public OrderRefundInterface getOrderRefundInterface() {
        return orderRefundInterface;
    }

    public void setOrderRefundInterface(OrderRefundInterface orderRefundInterface) {
        this.orderRefundInterface = orderRefundInterface;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderDetailBean.DataBean.OrderDOBean item) {
        RecyclerView recyclerView = helper.getView(R.id.rv);
        TextView ordernoTv=helper.getView(R.id.tv_orderno);
        ordernoTv.setText(" 订单号: "+item.getOrderno());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        recyclerView.setLayoutManager(linearLayoutManager);
        OrderDetailItemAdapter orderSecondAdapter = new OrderDetailItemAdapter(R.layout.item_orderdetail_goodsitem, null);
        orderSecondAdapter.setApplyRefundInterface(this);
        orderSecondAdapter.setStatus(item.getStatus());
        recyclerView.setAdapter(orderSecondAdapter);
        if(!ListUtils.isEmpty(item.getOrderItems())){
            orderSecondAdapter.setNewData(item.getOrderItems());
        }

    }

    @Override
    public void refund(int orderId, int orderItemId) {
        orderRefundInterface.service(orderId,orderItemId);
    }

    @Override
    public void schedule(int orderRefundId) {
        orderRefundInterface.serviceSchedule(orderRefundId);
    }

    public interface OrderRefundInterface{
        public void service(int orderId,int orderItemId);
        public void serviceSchedule(int orderRefundId);
    }
}
